package com.neusoft.serviceImpl;

import java.util.List;

import com.neusoft.dao.CartDao;
import com.neusoft.pojo.Cart;
import com.neusoft.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CartServiceImpl implements CartService {

	@Autowired
	private CartDao cartDao;
	
	//添加一条购物记录
	@Override
	public boolean addToCart(Integer pid, Integer pquantity, int uid) {
		// TODO Auto-generated method stub
		Integer i = cartDao.addToCart(pid, pquantity, uid);
		if(i == 1) {
			return true;
		}
		return false;
	}
	
	//删除购物的某一条记录
	@Override
	public Integer deleteCart(int cid) {
		// TODO Auto-generated method stub
		return cartDao.deleteCart(cid);
	}

	//获取购物车列表信息，用于分页
	@Override
	public List<Cart> getCartList(int uid, int currentPage, int pageSize) {
		// TODO Auto-generated method stub
		int start = (currentPage-1)*pageSize;
		return cartDao.getCartList(uid, start, pageSize);
	}

	//计算对应用户的购物车总数
	@Override
	public Integer countCart(int uid) {
		// TODO Auto-generated method stub
		return cartDao.countCart(uid);
	}

	//计算对应用户的购物车总金额
	@Override
	public Integer countPrice(int uid) {
		// TODO Auto-generated method stub
		return cartDao.countPrice(uid);
	}

}
